<template>
	<view class="content">
		<van-nav-bar
		  title="产品详情"
		  left-text="返回"
		  left-arrow
		  @click-left="onClickLeft"
		/>
<!-- 	<van-card
		class="vantCard"
		  :tag=this.tag
		  :title=this.nickname
		  :thumb=this.headimg
		/> -->
		<van-list
		  v-model:loading="this.loading"
		  :finished="this.finished"
		  finished-text="没有更多了"
		  @load="getCodeLogList()"
		>
			<van-cell center v-for="item in codeLogList" :value="this.formater(item.fac_name)" :label="item.usedate" is-link @click="navigateToItem(item.code)">
			  <!-- 使用 title 插槽来自定义标题 -->
			  <template #title>
				<span class="custom-title">产品编号：{{item.code}}</span>
				<van-tag :type="this.getStatusType(item.status)">{{this.getStatusText(item.status)}}</van-tag>
			  </template>
			</van-cell>
		</van-list>
	</view>
</template>

<script>
import axios from 'axios';
import { showToast } from 'vant';
	export default {
		data() {
			return {
				tag: '',
				openid: '',
				codeLogList: [],
				loading: false,
				finished: false,
				headimg: uni.getStorageSync('headimgurl'),
				// headimg:"https://thirdwx.qlogo.cn/mmopen/vi_32/PiajxSqBRaEJNfmdUC9sNSseiayaDw2rYdLEcQiaZjRiaHf5rticjFwZxG2PGdxZLVHlER5yia3ZHNicoox8JruwaVy2I1WVia8b6E8S8NV26zXduUH7f9lpO5wiarw/132",
				nickname: uni.getStorageSync('nickname')
				// nickname: "墨杨清竹"
			}
		},
		
		onLoad() {
			let openId = uni.getStorageSync('openid');
			if (!openId) {
				showToast("请返回并登录")
			}
			// else {
			// 	this.getCodeLogList(openId);
			// }
		},
		
		methods: {
			
			navigateToItem(productCode){
				uni.navigateTo({
					url: '/pages/productDetail/productDetail?productCode=' + productCode
				})
			},
			
			getStatusType(status) {
				switch (status) {
				        case 0:
				            return 'default';
				        case 1:
				            return 'primary';
						case 5:
						    return 'primary';
						case 6:
						    return 'success';
				        case 2:
				            return 'success';
				        case -1:
				            return 'danger';
				        case 4:
				            return 'warning';
				        default:
				            return '';
				    }
			},
			
			getStatusText(status) {
			      switch (status) {
			        case 0:
			          return '未使用';
			        case 1:
			          return '未激活';
			        case 2:
			          return '已激活';
			        case -1:
			          return '已删除';
			        case 4:
			          return '已作废';
					case 5:
						return '已出库';
					case 6:
						return '已入库';
			        default:
			          return '未知状态';
			      }
			},
			
			formater(fac) {
			  switch (fac) {
			    case "1":
			      return '柳州五菱汽车科技凸机生产厂';
			    case "2":
			      return '柳州五菱汽车科技有限公司';
			    case "3":
			      return '车合福家';
			    case "4":
			      return '五菱科技菱猫电动车';
			    case "5":
			      return '科菱商贸';
			    case "6":
			      return 'GXXF';
			    case "7":
			      return 'WLTE';
			    default:
			      return '默认工厂';
			  }
			},
			
			getCodeLogList(openId){
				axios({
				  method: 'post',
				  url: 'https://service.wulings.com/api/code/getCodeLogList',
				  data: {
				    "openid": 'o2fFU5jSlQuVgjQt5V55DIjed27g',
				  },
				  headers: {
				    'Content-Type': 'application/x-www-form-urlencoded'
				  }
				})
				.then(res => {
					console.log('当前的产品列表',res.data);
					setTimeout(() => {
						for (let i = 0; i < res.data.length; i++) {
									this.codeLogList.push(res.data[i]);
						        }
						        // 加载状态结束
						        this.loading = false;
						        // 数据全部加载完成
						        if (this.codeLogList.length >= res.data.length) {
						          this.finished = true;
						        }
								// console.log('加载完成',this.codeLogList);
					}, 1000);
				})
				.catch(err => {
				  // 请求失败时的回调函数
				  showFailToast('获取产品列表失败');
				});
				
				
			}
		}
	}
</script>

<style>
	.vantCard {
		margin-top: 25px;
		margin-bottom: 50px;
	}

</style>
